//
// Created by Tony on 2024/1/14.
//

#ifndef RUNTIME_COMMON_H
#define RUNTIME_COMMON_H

#include <cstdint>

namespace RtData {
class Object;
}

namespace Runtime {

constexpr char CLASS_INIT_METHOD_NAME[] = "<clinit>";
constexpr char OBJECT_INIT_METHOD_NAME[] = "<init>";
constexpr char OBJECT_CONSTRUCTOR_METHOD_NAME[] = "constructor";
constexpr char CLASS_MAIN_METHOD_NAME[] = "main";
constexpr char ENTRY_CLASS_NAME[] = "Entry";

enum class RtValueTag { UNKNOWN, INT64, FLT64, REF };

union RtValue {
    int64_t int64;
    double flt64;
    RtData::Object* ref;
};

struct RtTaggedValue {
    RtValueTag tag{RtValueTag::UNKNOWN};
    RtValue value{.int64 = 0};

    RtTaggedValue() = default;
    explicit RtTaggedValue(int64_t value) : tag(RtValueTag::INT64), value({.int64 = value}) {}
    explicit RtTaggedValue(double value) : tag(RtValueTag::FLT64), value({.flt64 = value}) {}
    explicit RtTaggedValue(RtData::Object* ref) : tag(RtValueTag::REF), value({.ref = ref}) {}
};

} // namespace Runtime

#endif // RUNTIME_COMMON_H
